<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin('jy_jdpm/member.index/');

$return=array();
$nickname=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']),'nickname');
$return['nickname']=$nickname;
if($_RQ['op']=='get'){
	$item=pdo_get('core_members',array('id'=>$_SESSION['uid']),array('realname'));
	$return['item']=$item;
	if($item['realname']){
		$return['read']=true;
	}
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['realname'] || !$post['pw1'] || !$post['pw2']){
		exi('请先设置好相关参数再提交！','error');
	}
	$item=pdo_get('core_members',array('id'=>$_SESSION['uid']),array('realname','password','salt'));
	$update=array();
	if(!$item['realname']){
		//设置账号、密码
		
		//检查账号是否已存在
		if(pdo_getcolumn('core_members',array('realname'=>$post['realname'],'uniacid'=>$_SESSION['uniacid']),'id')){
			exi('账号已存在，请更换！','error');
		}
		$salt=random(10);
		$update['realname']=$post['realname'];
	}else{
		if(!$post['pw']){
			exi('请输入原密码！','error');
		}
		$pw=get_password($post['pw'],$item['salt']);
		if($pw!=$item['password']){
			exi('原密码错误！','error');
		}
	}
	//修改密码
	if($post['pw1'] != $post['pw2']){
		exi('两次输入账号密码不一致！','error');
	}
	$salt=random(10);
	$update['password']=get_password($post['pw1'],$salt);
	$update['salt']=$salt;
	pdo_update('core_members',$update,array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！','','goback');
}